package com.sk.sourcecircle.activity.find.act;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.dyhdyh.widget.loading.dialog.LoadingDialog;
import com.sk.sourcecircle.R;
import com.sk.sourcecircle.base.BaseActivity;
import com.sk.sourcecircle.callback.HandleDataCallBack;
import com.sk.sourcecircle.dialog.TextTipDialogFragment;
import com.sk.sourcecircle.entity.EventDetailsBean;
import com.sk.sourcecircle.utils.AppApi;
import com.sk.sourcecircle.utils.MyUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by sk on 2018/1/6.
 */

public class ConfirmTaskWithoutMessageAct extends BaseActivity implements HandleDataCallBack {
    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.ed_name)
    EditText edName;
    @BindView(R.id.ed_phone)
    EditText edPhone;
    @BindView(R.id.event_bg)
    ImageView eventBg;
    @BindView(R.id.event_name)
    TextView eventName;
    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.tv_location)
    TextView tvLocation;
    @BindView(R.id.next)
    TextView next;

    private EventDetailsBean.DataBeanX eventDetailsBean;
    // 1雇佣，2满足需求
    private int type;
    private LoadingDialog loadingDialog;

    @Override
    protected int getContentView() {
        return R.layout.activity_confirm_with_out_message;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        loadingDialog = MyUtils.getLoadingDialog(mContext, false);
        eventDetailsBean = getIntent().getParcelableExtra("data");
        type = getIntent().getIntExtra("type", 0);
        edPhone.setText(MyUtils.getPhone(mContext));
        edName.setText(MyUtils.getName(mContext));
        Glide.with(mContext).load(eventDetailsBean.getHead_url()).into(eventBg);
        eventName.setText(eventDetailsBean.getName());
        tvTime.setText(eventDetailsBean.getStart_name());
    }

    @OnClick({R.id.back, R.id.next})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.next:

                List<EditText> editTexts = new ArrayList<>();
                edName.setTag("请输入姓名!");
                edPhone.setTag("请输入电话!");

                editTexts.add(edName);
                editTexts.add(edPhone);

                if (MyUtils.isFormat(mRootView, editTexts)) {
                    loadingDialog.show();
                    AppApi.createTaskOrder(eventDetailsBean.getActivity_id(), edPhone.getText().toString(), edName.getText().toString(), ConfirmTaskWithoutMessageAct.this, 0, ConfirmTaskWithoutMessageAct.this);
                }

                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == -1) {
            if (requestCode == 1) {
                String name = data.getStringExtra("name");
                String phone = data.getStringExtra("phone");
                edName.setText(name);
                edPhone.setText(phone);
            }
        }
    }

    @Override
    public void sure() {
        super.sure();
        finish();
    }

    @Override
    public void handlerSuccessData(String result, int tag) {
        loadingDialog.cancelDialog();
        TextTipDialogFragment textTipDialogFragment = new TextTipDialogFragment();
        textTipDialogFragment.setMyCallBack(ConfirmTaskWithoutMessageAct.this);
        if (type == 1) {
            textTipDialogFragment.setContent("您的热心我们已经收到\n" +
                    "主办方稍后会筛选出合适的人");
        } else {
            textTipDialogFragment.setContent("您的雇佣我们已经收到\n" +
                    "主办方稍后会筛选出合适的人");
        }
        textTipDialogFragment.show(getSupportFragmentManager(), "tip");
    }

    @Override
    public void handlerFailData(String failString, int tag) {
        loadingDialog.cancelDialog();
    }

    @Override
    public void handleErrorData(String error, int tag) {
        loadingDialog.cancelDialog();
    }
}
